import React, { useEffect, useRef } from 'react';
import hljs from 'highlight.js/lib/core';
import 'highlight.js/styles/github-dark.css';
import 'highlight.js/lib/languages/json';

// 导入其他所需的语言样式文件

const CodeHighlighter = ({ code, language }) => {
    const codeRef = useRef(null);

    useEffect(() => {
        hljs.highlightBlock(codeRef.current);
    }, [code]);

    return (
        <pre>
      <code ref={codeRef} className={language}>
        {code}
      </code>
    </pre>
    );
};

export default CodeHighlighter;
